﻿using System;
using System.Collections.Generic;

namespace MoneyBook {
	public sealed class Pages {

		private Pages root = null;
		
		public Pages() {
			this.root = this;
			this.Views = new ViewsPages(this.root);
		}
		
		public ViewsPages Views { get; private set; }

		public class ViewsPages {
		
			private Pages root = null;
			
			public ViewsPages(Pages root) {
				this.root = root;
			}

			public const string CreateUserView = "/Views/CreateUserView.xaml";

			public Uri CreateUserViewUri {
				get {
					return GetCreateUserViewUri(null);
				}
			}

			public Uri GetCreateUserViewUri(Dictionary<string, string> parameters) {
				return this.root.GetUri(CreateUserView, parameters);
			}

			public const string LoginView = "/Views/LoginView.xaml";

			public Uri LoginViewUri {
				get {
					return GetLoginViewUri(null);
				}
			}

			public Uri GetLoginViewUri(Dictionary<string, string> parameters) {
				return this.root.GetUri(LoginView, parameters);
			}

			public const string MainView = "/Views/MainView.xaml";

			public Uri MainViewUri {
				get {
					return GetMainViewUri(null);
				}
			}

			public Uri GetMainViewUri(Dictionary<string, string> parameters) {
				return this.root.GetUri(MainView, parameters);
			}
		}
	
		
		public Uri GetUri(string pageUri, Dictionary<string, string> parameters) {
	
			string result = pageUri;

			if(parameters != null && parameters.Count > 0) {
				List<string> parameterKeyValues = new List<string>();
				foreach(string key in parameters.Keys) {
					parameterKeyValues.Add(string.Format("{0}={1}", key, parameters[key]));
				}
				result += "?" + string.Join("&", parameterKeyValues.ToArray());
			}
			return new Uri(result, UriKind.RelativeOrAbsolute);
		}
	}
	
	public sealed class PagesWrapper {
		
		private static Pages pages = new Pages();
		
		public Pages Pages {
			get {return pages;}
		}
		
		public static Pages Current {
			get {return pages;}
		}
		
	}
}
